//
//  sendqq.m
//  tcpoctest
//
//  Created by 123456 on 13-8-7.
//  Copyright (c) 2013年 gump. All rights reserved.
//

#import "sendqq.h"
#import "bigHeadImageDataSource.h"

@implementation sendqq

-(void)sendQQConfig:(NSString *)strOpenid
             withPS:(NSString *)strps
           withName:(NSString *)strname
            withSex:(char)csex
            withAge:(char)cage
        withProvice:(char)cprovice
           withCity:(char)ccity
           withUDID:(NSString *)strudid
        withChannel:(NSString *)strchannel
{
    //发送:主索引10char(1)，副索引11char(1)，openid长度char(1),
    //openid值char(x),密码char(32),昵称长度char(1),
    //昵称char(X),性别char(1)1男2女,年龄char(1)0-255岁,
    //省char(1),市char(1)设备UDID长度char(1),设备UDIDchar(x),
    //小头像长度int,小头像char(X),大头像长度int,大头像char(x),
    //渠道ID长度char(1),渠道IDchar(x)
    
    
    if ([DataControl shareControl].bigHIDS.UserBigImage == nil
        || [DataControl shareControl].iImage == nil) {
        return;
    }
    
    NSData *imageData = UIImageJPEGRepresentation([DataControl shareControl].iImage, JPG_COMPRESS_RATE);
    int imagelength = [imageData length];
    NSData *bigimagedata = UIImageJPEGRepresentation([DataControl shareControl].bigHIDS.UserBigImage, JPG_COMPRESS_RATE);
    int bigimagelength = [bigimagedata length];
    
    int l = CHAR_PL * 10 +
            INT_PL * 3 +
            [strOpenid length] +
            [strps length] +
            [strudid length] +
            imagelength +
            bigimagelength +
            [strchannel length];
    
    [self initDataByLength:l];
    
    [sb WriteChar:[strOpenid length]];
    [sb WriteString:strOpenid withLength:[strOpenid length]];
    
    [sb WriteChar:[strps length]];
    [sb WriteString:strps withLength:[strps length]];
    
    [sb WriteChar:[strname length]];
    [sb WriteString:strname withLength:[strname length]];
    
    [sb WriteChar:csex];
    [sb WriteChar:cage];
    [sb WriteChar:cprovice];
    [sb WriteChar:ccity];
    
    [sb WriteChar:[strudid length]];
    [sb WriteString:strudid withLength:[strudid length]];
    
    [sb WriteInt:[imageData length] withNTT:NTT_SMALL2BIG];
    [sb WriteData:(char *)[imageData bytes] withLength:[imageData length]];
    
    [sb WriteInt:[bigimagedata length] withNTT:NTT_SMALL2BIG];
    [sb WriteData:(char *)[bigimagedata bytes] withLength:[imageData length]];
    
    [sb WriteChar:[strchannel length]];
    [sb WriteString:strchannel withLength:[strchannel length]];
    
    [self Package];
}

@end
